﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Entities.IRepository;
using DAL.Admin;
using Entities;
using BLL.BLL;

namespace WindowsForms.Admin
{
    public partial class FormTKNhanVien : Form
    {
        int nums = 8;
        int page = 1;
        int tong;
        public INhanVienRepository nv = new BLTNhanVienRepository();
        public FormTKNhanVien()
        {
            InitializeComponent();
            dataGridvewnv.AutoGenerateColumns = false;
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void FormTKNhanVien_Load(object sender, EventArgs e)
        {
          
            tong = ManagerForm.TongTrang(nv.LayTatCa().Count, nums);
            LoadNhanVien(getPage(page));

            tbdl.Text = page + " / " + tong;
        }
        public void LoadNhanVien(List<NhanVien> ds)
        {
            dataGridvewnv.DataSource = ds;
        }
        public List<NhanVien> getPage(int page)
        {
            var query = from c in nv.LayTatCa()
                           .Skip(nums * page - nums).Take(nums)
                        select c;
            return query.ToList();


        }

        private void btlui_Click(object sender, EventArgs e)
        {
            if (page >= 2)
            {
                page--;
                tbdl.Text = page + " / " + tong;
                LoadNhanVien(getPage(page));
            }
        }

        private void bttien_Click(object sender, EventArgs e)
        {
            if (page < tong)
                page++;

            if (page <= tong)
            {
                tbdl.Text = page + " / " + tong;
                LoadNhanVien(getPage(page));

            }
        }

        private void tbdl_KeyDown(object sender, KeyEventArgs e)
        {
            int t;
            if (e.KeyData == Keys.Enter)
            {
                try
                {
                    t = Convert.ToInt32(tbdl.Text);
                    if (t <= tong && t > 0)
                    {
                        LoadNhanVien(getPage(t));
                        tbdl.Text = t + " / " + tong;
                        page = t;
                    }
                }
                catch (Exception)
                {

                    MessageBox.Show("Nhâp Trang Muốn Đến");
                }

            }
        }

    
    }
}
